package app.web.galgame.collects;

import java.util.HashSet;
import java.util.Set;

import cn.lily.com.db.DBFactory;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.exception.YaconException;
import cn.lily.com.lang.DeCode;
import cn.lily.esb.enums.EnumManager;
import cn.lily.web.page.BusinessPage;
import cn.lily.web.widget.page.TPanel;
import cn.lily.web.widget.standard.TButton;
/**
 * 游戏采集Edit页面
 * @author JiaJ
 * @date 2018年5月31日
 *
 */
public class GalGameEdit extends BusinessPage {

	@Override
	public void page_onLoad() throws YaconException {
		
		TPanel galgameEditPanel = Panel("galgameEditPanel");
		galgameEditPanel.creatToolbar().setBarText("GalGame编辑");
		
		Form("galgameEditForm").setDictTable("LEO_GALGAME_INFO_JPS");
		
		Form("galgameEditForm").createFormCell(Input("GAME_NAME"),6);
		
		//数据按钮添加
		TButton sadBrotherBtn = new TButton("sadBrotherBtn");
		sadBrotherBtn.setLabel("忧郁的弟弟");
		sadBrotherBtn.setViewClick("sadBrotherBtn_click");
		sadBrotherBtn.setState("danger");
		sadBrotherBtn.setViewType("label");
		Form("galgameEditForm").createFormCell(sadBrotherBtn,6);
		
		TButton hgameCNBtn = new TButton("hgameCNBtn");
		hgameCNBtn.setLabel("HgameCN");
		hgameCNBtn.setViewClick("hgameCNBtn_click");
		hgameCNBtn.setState("warning");
		hgameCNBtn.setViewType("label");
		Form("galgameEditForm").addFormCell(hgameCNBtn);
		
		TButton bangumiBtn = new TButton("bangumiBtn");
		bangumiBtn.setLabel("bangumi");
		bangumiBtn.setViewClick("bangumiBtn_click");
		bangumiBtn.setState("success");
		bangumiBtn.setViewType("label");
		Form("galgameEditForm").addFormCell(bangumiBtn);
		
		TButton yuinyaBtn = new TButton("yuinyaBtn");
		yuinyaBtn.setLabel("yuinya");
		yuinyaBtn.setViewClick("yuinyaBtn_click");
		yuinyaBtn.setBackColor("#33CCFF");
		yuinyaBtn.setViewType("label");
		Form("galgameEditForm").addFormCell(yuinyaBtn);
		
		Form("galgameEditForm").createFormRow();
		
		Form("galgameEditForm").createFormCell(Check("GAME_TYP").setEnumDetail(EnumManager.getTableEnum("GAME_TYP")).setInsertDefaultValue("ADV"));		
		Form("galgameEditForm").createFormCell(Radio("GAME_LANG").setInsertDefaultValue("02"));
		Form("galgameEditForm").createFormCell(Radio("GAME_VISUAL").setInsertDefaultValue("01"));
		Form("galgameEditForm").createFormRow();
		
		Drop("DISK_ID").setEnumDetail(EnumManager.getDBEnum("select DISK_ID,DISK_NAM from ${schema}.LEO_DISK_INFO where DISK_STATUS='1'"));
		Form("galgameEditForm").createFormCell(Drop("DISK_ID"),3);
		Form("galgameEditForm").createFormCell(Input("GAME_STORE_PATH"),6);
		Form("galgameEditForm").createFormCell(Input("GAME_SIZE"),3);
		Form("galgameEditForm").createFormRow();
		
		Form("galgameEditForm").createFormCell(Input("GAME_PRO_TIME"));
		Form("galgameEditForm").createFormCell(Input("GAME_TAGS"));
		Form("galgameEditForm").createFormRow();
		
		Form("galgameEditForm").createFormCell(Input("GAME_FACTORY"));
		Form("galgameEditForm").createFormCell(Input("GAME_FIRST"));
		Form("galgameEditForm").createFormRow();
		
		Form("galgameEditForm").createFormCell(TextArea("GAME_NAME_PLUS").setAreaRow(3));
		Form("galgameEditForm").createFormRow();
		
		Form("galgameEditForm").createFormCell(TextArea("GAME_INTRU").setAreaRow(12));
		Form("galgameEditForm").createFormRow();
		
		Form("galgameEditForm").createFormCell(TextArea("GEME_MEMO").setAreaRow(6));
		Form("galgameEditForm").createFormRow();
		
		galgameEditPanel.createPanelCell(Form("galgameEditForm"));
		galgameEditPanel.creatStatusBar().addElement(Button("save"));
		galgameEditPanel.getStatusBar().addElement(Button("exit"));
		getPage().addElement(galgameEditPanel);
		
	}
	
	public void sadBrotherSearch(){
		if(this.getViewTable().next()){
			String gameID = this.getViewTable().getString("gameID");
			DataTable table = DBFactory.getActionDB().executeQueryTable("select * from ${schema}.LEO_SAD_BROTHER_INFO where LEO_GAL_ID='"+gameID+"'");
			this.setDataTable(table);
		}else{
			this.setSelfMessage("Error");
		}
	}
	
	public void bangumiSearch(){
		if(this.getViewTable().next()){
			String gameID = this.getViewTable().getString("gameID");
			DataTable table = DBFactory.getActionDB().executeQueryTable("select * from ${schema}.LEO_BANGUMI_GAME_INFO where GAME_ID='"+gameID+"'");
			this.setDataTable(table);
		}else{
			this.setSelfMessage("Error");
		}
	}
	
	public void yuinyaSearch(){
		if(this.getViewTable().next()){
			String gameID = this.getViewTable().getString("gameID");
			DataTable table = DBFactory.getActionDB().executeQueryTable("select * from ${schema}.LEO_YUINYA_GAL_INFO where GAME_ID='"+gameID+"'");
			this.setDataTable(table);
		}else{
			this.setSelfMessage("Error");
		}
	}
	
	public void hgameCNSearch(){
		if(this.getViewTable().next()){
			String gameID = this.getViewTable().getString("gameID");
			DataTable table = DBFactory.getActionDB().executeQueryTable("select GAME_NAME,GAME_NAME_OTH,GAME_FACTORY,"
			         + "to_char(GAME_DATE,'yyyy-mm-dd') GAME_DATE,"
			         + "GAME_TAG,GAME_ID,GAME_PICTOR,GAME_WRITER,GAME_MEMO,"
			         + "GAME_URL,GAME_CAST,GAME_MUSIC,GAME_SINGER "
			         + "from ${schema}.LEO_HGAMECN_INFO where GAME_ID='"+gameID+"'");
			this.setDataTable(table);
		}else{
			this.setSelfMessage("Error");
		}
	}
	
	public void tagsClear(){
		if(this.getViewTable().next()){
			String gameTags = DeCode.decode(this.getViewTable().getString("gameTags"));
			String[] tags = gameTags.split(",");
			Set<String> tagSets = new HashSet<String>();
			for(String tag:tags){
				tagSets.add(tag);
			}
			String retTags = "";
			for(String tagst:tagSets){
				retTags += ","+ tagst;
			}
			if(!"".equals(retTags)){
				retTags = retTags.substring(1);
			}
			
			this.setSelfMessage("#"+DeCode.encode(retTags));
		}else{
			this.setSelfMessage("");
		}
	}

}
